package com.woniu.p2p.serviceImpl;

import com.woniu.p2p.entity.*;
import com.woniu.p2p.mapper.*;
import com.woniu.p2p.service.BorrowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * borrowServiceImpl
 *
 *
 */
@Service
public class BorrowServiceImpl implements BorrowService {
    @Autowired
    LoansUsemethodMapper loansUsemethodMapper;
    @Autowired
    LoansMapper loansMapper;

    @Autowired
    InvestRepayMapper investRepayMapper;

    @Autowired
    UserZongMapper userZongMapper;

    @Autowired
    UserMonloansMapper userMonloansMapper;

    @Autowired
    UserLoansMapper userLoansMapper;

    @Autowired
    UserMapper userMapper;

    @Override
    public List<LoansUsemethod> findAllLoansUsemethod() {
        return loansUsemethodMapper.selectAll();
    }

    @Override
    @Transactional
    public int addLoansAnduserZong(Loans loans, UserZong userZong) {
        //添加贷款表
        loansMapper.insert(loans);
        //添加用户总表
        userZongMapper.insert(userZong);
        return 0;
    }
    @Override
    public List<InvestRepay> findAllInvestRepay() {
        return investRepayMapper.selectAll();
    }

    @Override
    public int addLoansMouth(UserMonloans userMonloans) {
        return userMonloansMapper.insert(userMonloans);
    }

    @Override
    public Loans findLoansById(Integer id) {
        return loansMapper.selectByPrimaryKey(id);
    }

    @Override
    public UserLoans findUserLoans(Integer id) {
        return userLoansMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateUserLoans(UserLoans userLoans) {
        return userLoansMapper.updateByPrimaryKey(userLoans);
    }

    @Override
    public User findByUserId(Integer userId) {
        return userMapper.selectByPrimaryKey(userId);
    }

    @Override
    public int updateLoans(Loans loans) {
        return loansMapper.updateByPrimaryKey(loans);
    }

    @Override
    public int updateUser(User user) {
        return userMapper.updateByPrimaryKey(user);
    }


}
